<template>
  <div>
    <van-nav-bar
        title='修改密码'
        placeholder
        fixed
        left-arrow
        @click-left="goBack"
    />
    <div>
      <van-field
          v-model="o_password"
          label="输入当前密码"
          placeholder="输入当前密码"
          input-align="right"
          type="password"
      />
      <van-field
          v-model="n_password"
          label="输入新密码"
          placeholder="输入新密码"
          input-align="right"
          type="password"
      />
      <van-field
          v-model="r_password"
          label="再次输入新密码"
          placeholder="再次输入新密码"
          input-align="right"
          type="password"
      />
    </div>
    <div>
      <van-button round block type="info" native-type="submit" style="width: 150px;margin-left: 110px" @click="submit">提交</van-button>
    </div>
  </div>

</template>

<script>
import axios from "axios";

export default {
  name: "ChangingPassword",
  data(){
    return{
      o_password:'',
      n_password:'',
      r_password:'',
      user_id:'',
    }
  },
  created() {
    var _this = this
    _this.user_id = _this.$route.query.user_id
  },
  methods:{
    goBack() {
      this.$router.push("account-safety?user_id="+this.user_id);
    },
    submit(){
      var _this = this
      if(_this.r_password!=_this.n_password){
        alert("两次输入的密码不一致!")
        window.location.reload()
      }
      else if(_this.n_password==""){
        alert("密码不能为空!");
        window.location.reload()
      }
      else {
        _this.axios({
          method:"get",
          url: "/user_edit/password_changing/"+_this.o_password+"&"+_this.user_id+"&"+_this.n_password,
        }).then(function (rep){
          if(rep.data.message=="成功") {
            alert("密码修改成功!")
            _this.$store.dispatch("userinfo/clearnuserinfo")
            window.location.reload();
          }
          else if(rep.data.message="原密码输入不正确!"){
            alert("原密码输入不正确!");
            _this.o_password = '';
            _this.n_password = '';
            _this.r_password = '';
          }
        })
      }
    },

  }
}
</script>

<style scoped>

</style>